home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / introduction / example2.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  3KB  |  95 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Introduction                Tulevagen 22       */
  8. /* File:    Example2.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-09-24                                       */
  11. /* Version: 1.1                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to allocate some memory which    */
  21. /* has to be long word aligned. We will allocate a FileInfoBlock  */
  22. /* structure in this example, but the procedure of allocating     */
  23. /* long word aligned memory is the same for all types of objects. */
  24.  
  25.  
  26.  
  27. /* Include the normal dos header file: */
  28. #include <libraries/dos.h>
  29.  
  30. /* Include memory definitions: (MEMF_ANY...) */
  31. #include <exec/memory.h>
  32.  
  33. /* Now we include the necessary function prototype files:         */
  34. #include <clib/dos_protos.h>       /* General dos functions...    */
  35. #include <clib/exec_protos.h>      /* System functions...         */
  36. #include <stdio.h>                 /* Std functions [printf()...] */
  37. #include <stdlib.h>                /* Std functions [exit()...]   */
  38.  
  39.  
  40.  
  41. /* Set name and version number: */
  42. UBYTE *version = "$VER: AmigaDOS/AmigaDOS/Example2 1.1";
  43.  
  44.  
  45.  
  46. /* Declared our own function(s): */
  47. int main( int argc, char *argv[] );
  48.  
  49.  
  50.  
  51. /* The main function: */
  52.  
  53. int main( int argc, char *argv[] )
  54. {
  55.   /* A pointer to our memory which we will allocate: */
  56.   struct FileInfoBlock *my_fib_ptr;
  57.  
  58.  
  59.  
  60.   /* Allocate some memory. The memory will be long word aligned   */
  61.   /* which means that the data will start (and end) on a complete */
  62.   /* 32-bit address (even word address, on a 4 byte boundary).    */
  63.   my_fib_ptr = AllocMem( sizeof( struct FileInfoBlock ),
  64.     MEMF_ANY | MEMF_CLEAR );
  65.  
  66.  
  67.   /* Have we successfully allocated the memory? */
  68.   if( my_fib_ptr == NULL )
  69.   {
  70.     /* Not enough memory! Inform the user and quit: */
  71.     printf( "Could not allocate enough memory!\n" );
  72.  
  73.     /* Exit with an error code: */
  74.     exit( 20 );
  75.   }
  76.  
  77.  
  78.  
  79.   /* You can now use the memory... */
  80.   printf( "We have successfully allocated a FileInfoBlock structure!\n" );
  81.   
  82.   
  83.  
  84.   /* Deallocate the memory when we do not need it any more: */
  85.   FreeMem( my_fib_ptr, sizeof( struct FileInfoBlock ) );
  86.  
  87.   /* Remember that you may not use the memory any */
  88.   /* more after you have deallocated it!          */
  89.   printf( "The memory has been deallocated!\n" );
  90.  
  91.   /* The End (0 = success): */
  92.   exit( 0 );
  93. }
  94.  
  95.